﻿using System;
using System.Windows.Forms;

namespace AuthenticationTool
{
    public partial class PinForm : Form
    {

        public string PinCode
        {
            get { return PinTextBox.Text; }
        }

        public PinForm()
        {
            InitializeComponent();
        }

        public PinForm(Form parentForm)
        {
            Owner = parentForm;
            InitializeComponent();
        }

        private void ApproveButton_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
            Close();
        }

        private void PinForm_Activated(object sender, EventArgs e)
        {
            PinTextBox.Focus();
        }

        private void PinTextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar.Equals(Keys.Escape))
            {
                CancelAuthButton.PerformClick();
            }

            if (Char.IsSymbol(e.KeyChar) || Char.IsLetter(e.KeyChar) || Char.IsPunctuation(e.KeyChar))
            {
                e.Handled = true;
            }
        }

        private void PinTextBox_TextChanged(object sender, EventArgs e)
        {
            ApproveButton.Enabled = PinTextBox.Text.Length > 0;
        }
    }
}
